package controller.api;
import com.alibaba.fastjson.JSONObject;
import com.jfinal.aop.Before;
import com.jfinal.aop.Inject;
import com.jfinal.kit.Ret;
import com.jfinal.kit.StrKit;

import common.inter.ServicerStationInter;
import common.inter.StaffStationInter;
import model.Station;
import model.WaterCollector;
import service.WaterCollectorService;

public class ApiWaterCollectorController extends BaseApiController {
	@Inject WaterCollectorService waterCollectorService ;
	
	@Before(ServicerStationInter.class)
	public void info() {
		Station station = getStation();
		WaterCollector waterCollector = WaterCollector.dao.findFirstByStationId(station.getId());
        set("data", waterCollector );
        if (null != waterCollector && StrKit.notBlank(waterCollector.getChannelParams())) {
			set("channelList", JSONObject.parseArray(waterCollector.getChannelParams()));
		}
        renderJson();
	}

	@Before(StaffStationInter.class)
	public void save() {
		WaterCollector waterCollector = getModel(WaterCollector.class , "x");
        Ret ret = waterCollectorService.save(waterCollector , getStation() , getStaff() );
        renderJson(ret);
	}
}
